package com.axjy.base.service.impl;
import com.axjy.base.feige.ItemFeignClient;
import com.axjy.base.mapper.ImageMpper;
import com.axjy.base.service.ImageService;
import com.axjy.base.vo.BannerVo;
import com.axjy.comm.pojo.TpImage;
import com.axjy.comm.pojo.TpItem;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

@Service("imageService")
public class ImageServiceimpl implements ImageService {
    @Resource
    private ImageMpper imageMpper;
    @Resource
    private ItemFeignClient itemFeignClient;
    @Override
    public List<BannerVo> queryBanner() {
        QueryWrapper<TpImage> wrapper= Wrappers.query();
        wrapper.eq("type",1);
        wrapper.orderByAsc("sort");
        List<TpImage> list=imageMpper.selectList(wrapper);

        List<BannerVo> voList=new ArrayList<>();

        for (TpImage tpImage:list){
            BannerVo vo=new BannerVo();
            vo.setId(tpImage.getId());
            vo.setImgUrl(tpImage.getImgUrl());
            vo.setTargetId(tpImage.getTargetId());
            TpItem tpItem=itemFeignClient.findByTargetId(tpImage.getTargetId());
            vo.setItemName(tpItem.getItemName());
            vo.setMinPrice(tpItem.getMinPrice());
            voList.add(vo);
        }
       /* List<BannerVo> voList=list.stream().map(tpImage -> {
            BannerVo vo=new BannerVo();
            BeanUtils.copyProperties(tpImage,vo);
            TpItem tpItem=itemFeignClient.findByTargetId(tpImage.getTargetId());
            BeanUtils.copyProperties(tpItem,vo);
            return vo;
        }).collect(Collectors.toList());*/
        return voList;
    }
}
